package com.soilflow.info.service.impl;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.soilflow.common.domain.DahuCarpooling;
import com.soilflow.common.domain.DahuRouteStop;
import com.soilflow.common.domain.dto.DahuRouteStopDto;
import com.soilflow.common.domain.vo.DahuRouteStopVo;
import com.soilflow.common.utils.StringUtils;
import com.soilflow.info.mapper.DahuRouteStopMapper;
import com.soilflow.info.service.IDahuCarpoolingService;
import com.soilflow.info.service.IDahuRouteStopService;
import com.soilflow.info.service.IDahuStopService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author party
 * @date 2023-10-30
 */
@Service
public class DahuRouteStopServiceImpl extends ServiceImpl<DahuRouteStopMapper,DahuRouteStop> implements IDahuRouteStopService {
    @Resource
    private DahuRouteStopMapper dahuRouteStopMapper;
    @Autowired
    private IDahuStopService dahuStopService;
    @Autowired
    private IDahuCarpoolingService dahuCarpoolingService;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public DahuRouteStop selectDahuRouteStopById(Long id) {
        DahuRouteStop dahuRouteStop = dahuRouteStopMapper.selectDahuRouteStopById(id);
        return dahuRouteStop;
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @return 【请填写功能名称】
     */
    @Override
    public List<DahuRouteStopVo> selectDahuRouteStopList(DahuRouteStopVo dahuRouteStopvo) {
        List<DahuRouteStopVo> routeStopList = this.baseMapper.getDahuRouteStopList(dahuRouteStopvo);
        return routeStopList;
    }

    /**
     * 新增【发布拼车信息】
     * 
     * @param 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertDahuRouteStop(DahuRouteStopDto dahuRouteStopdto) {
        String startTime = dahuRouteStopdto.getStartTime();
        DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            Date date = fmt.parse(startTime);
            System.out.println("date = " + date);
            DahuRouteStop dahuRouteStop = new DahuRouteStop();
            BeanUtils.copyProperties(dahuRouteStopdto,dahuRouteStop);
            dahuRouteStop.setStartTime(date);
            return dahuRouteStopMapper.insert(dahuRouteStop);
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
//        return dahuRouteStopMapper.insert(dahuRouteStop);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param dahuRouteStop 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateDahuRouteStop(DahuRouteStop dahuRouteStop)
    {
        return dahuRouteStopMapper.updateById(dahuRouteStop);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteDahuRouteStopByIds(Long[] ids) {
        return dahuRouteStopMapper.deleteDahuRouteStopByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteDahuRouteStopById(Long id)
    {
        return dahuRouteStopMapper.deleteDahuRouteStopById(id);
    }
}
